/**
 * 
 */
package escola.spring.datasource;

import org.apache.commons.lang3.StringUtils;

/**
 * @author Jonathan
 *
 */
public class DataSourceContextHolder {
	
	private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
	
	private static String serverURL;
	
	public static void setDataSourceName(String dataSourceName) {
		if (StringUtils.isBlank(dataSourceName)) {
			throw new RuntimeException("dataSourceName cannot be null or blank");
		}
		contextHolder.set(dataSourceName.trim().toLowerCase());
	}
	
	public static String getDataSourceName() {
		return contextHolder.get();
	}
	
	public static void clear() {
		contextHolder.remove();
	}

	public static String getServerURL() {
		return serverURL;
	}

	public static void setServerURL(String serverURL) {
		DataSourceContextHolder.serverURL = serverURL;
	}
	
	public static String getDatabaseURL() {
		return getServerURL() + getDataSourceName();
	}

}
